using System;
using Provausio.Common.Objects;
using TrainingManagement.api.Models.Data.CRUD;
using TrainingManagement.api.Models.Data.CRUD.DepartmentTree;

namespace TrainingManagement.api.Models.BusinessLogic.DepartmentTree
{
    public class DepartmentTreeUpdateOperation : BusinessOperation<BusinessObjects.DepartmentTree, bool>
    {
        readonly DepartmentTreeUpdateDataSource _departmentTreeUpdate = new DepartmentTreeUpdateDataSource();

        public override bool Run(BusinessObjects.DepartmentTree input)
        {
            if (_departmentTreeUpdate.Execute(input))
                return true;
            throw new Exception(string.Format("{0}>{1} failed to update!", input.ParentTitle, input.ChildTitle));
        }
    }
}